package model

import (
	"gitee.com/carollia/data-sdk-go/utils"
	"errors"
)

// 用户信息
type User struct {
	Type       string                 `json:"type"`
	Time       int64                  `json:"time"`
	Uid        string                 `json:"uid"`
	UidType    string                 `json:"uid_type"`
	Properties map[string]interface{} `json:"properties"`
}

func (u *User) Normalize() error {
	if u.Type != "profile_set" && u.Type != "profile_delete" && u.Type != "profile_create"{
		return errors.New("property [Type] is not profile_set or profile_delete or profile_create")
	}
	u.Time = utils.GetCNTimeNow()
	// check uid
	if u.Uid == "" || len(u.Uid) == 0 {
		return errors.New("property [uid] can't be empty")
	}
	if len(u.Uid) > 255 {
		return errors.New("the max length of property [uid] is 255")
	}

	if u.Properties == nil {
		u.Properties = map[string]interface{}{}
	}

	return nil
}
